package com.qfedu.microuser.user.controller;

import com.qfedu.common.core.annotation.NoLogin;
import com.qfedu.common.core.common.R;
import com.qfedu.microuser.user.param.LoginParam;
import com.qfedu.microuser.user.param.RegisterParam;
import com.qfedu.microuser.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Classname LoginController
 * @Description TODO
 * @Date 2025-05-21 16:16
 * @Created by 老任与码
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Resource
    private UserService userService;

    /**
     * 注册
     *
     * @param registerParam
     * @return
     */
    @NoLogin
    @PostMapping("/register")
    public R register(@Valid @RequestBody RegisterParam registerParam) {
        System.out.println("registerParam: " + registerParam);
        userService.register(registerParam);
        return R.ok();
    }

    @PostMapping("/login")
    @NoLogin
    public R login(@RequestBody LoginParam loginParam) {
        String token = userService.login(loginParam);
        return R.ok(token);
    }

    @NoLogin
    @GetMapping("/code")
    public R code(String phone) {
        userService.createCode(phone);
        return R.ok();
    }
}
